package view.renderer
{
	import com.common.Color;
	import com.util.MakeChildrenUtil;
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import xm.view.item.ViewListItemRenderer;
	
	
	/**
	 * <br> 클래스 설명 : </br>
	 * @author 강석민
	 */	
	public class Renderer14 extends ViewListItemRenderer
	{
		//-----------------------------------------------------------------------------------
		// public vars
		//-----------------------------------------------------------------------------------
		//-----------------------------------------------------------------------------------
		// protected / internal vars
		//-----------------------------------------------------------------------------------
		//-----------------------------------------------------------------------------------
		// private vars
		//-----------------------------------------------------------------------------------
		//==================================
		//		Data Vars
		private var menuId			: String;
		private var menuNm 			: String;
		private var cnt 			: String;
		//==================================
		private var leftIcon 		: MovieClip;
		private var titleTf 		: TextField;
		//-----------------------------------------------------------------------------------
		// public functions
		//-----------------------------------------------------------------------------------
		
		/**
		 * constructor 
		 */	
		public function Renderer14()
		{
			super();
		}
		
		/**
		 * commitProperties
		 */		
		override public function commitProperties():void
		{
			super.commitProperties();
		}
		
		/**
		 * updateDisplayList
		 */		
		override public function updateDisplayList( enforce : Boolean = false ):void
		{
			super.updateDisplayList(enforce);
		}
		/**
		 * <br>dataProvider 에 값을 반영하면 바로 apply 에 들어온다.</br>
		 * apply - data 를 화면에 반영하는 과정.
		 */		
		override public function apply():void
		{
			super.apply();
			
			this.backgroundAlpha = 0;
			
			this.borderTopAlpha = 1;
			this.borderTopThickness = 1;
			this.borderTopColor = Color.RED;
			
			this.borderBottomAlpha = 1;
			this.borderBottomColor = Color.BLUE;
			this.borderBottomThickness = 1;
			
			//========================================
			// 리셋
			//========================================
			titleTf.text = "";
			if( leftIcon && this.contains( leftIcon ) ) this.removeChild( leftIcon );
			
			//========================================
			// 데이터 읽기
			//========================================
			menuId				= this.data.menuId as String;
			menuNm 				= this.data.menuNm as String;
			cnt 				= this.data.cnt as String;
			//========================================
			// 데이터 적용
			//========================================
			var gap : int = 30;
			
			if( cnt == "0" )
			{
				leftIcon			= new ICON_NEW_SMALL;
			}else
			{
				leftIcon			= new ICON_SYNC_SMALL;
			}
			if( leftIcon && this.contains( leftIcon ) == false ) 
			{
				leftIcon.x = 10;
				leftIcon.y = ( this.viewHeight - leftIcon.height ) /2;;
				addChild( leftIcon );
			}
			
			titleTf.text = menuNm;
			titleTf.x = leftIcon.x + leftIcon.width + gap;
			titleTf.y = ( this.viewHeight - titleTf.height ) /2;
			
			
		}
		
		//-----------------------------------------------------------------------------------
		// life cycle functions
		//-----------------------------------------------------------------------------------
		
		/**
		 * createChildren
		 */		
		override public function createChildren():void
		{
			super.createChildren();
			
			titleTf = MakeChildrenUtil.makeTextField( "" );
			addChild( titleTf );
			
			this.addEventListener( MouseEvent.MOUSE_DOWN, onListDown);
			this.addEventListener( MouseEvent.MOUSE_UP, onListUp );
			this.addEventListener( MouseEvent.CLICK , onListClick );
		}
		
		/**
		 * createComplete
		 */		
		override public function creationComplete():void
		{
			super.creationComplete();
		}
		
		/**
		 * add
		 */		
		override public function add():void
		{
			super.add();
		}
		
		/**
		 * remove
		 */		
		override public function remove():void
		{
			super.remove();
		}
		
		/**
		 * destroy
		 */		
		override public function destroy():void
		{
			super.destroy();
		}
		
		//-----------------------------------------------------------------------------------
		// setter / getter
		//-----------------------------------------------------------------------------------
		//-----------------------------------------------------------------------------------
		// protected functions
		//-----------------------------------------------------------------------------------
		//-----------------------------------------------------------------------------------
		// internal functions
		//-----------------------------------------------------------------------------------
		//-----------------------------------------------------------------------------------
		// private functions
		//-----------------------------------------------------------------------------------
		//-----------------------------------------------------------------------------------
		// event handler
		//-----------------------------------------------------------------------------------
		/**
		 *		마우스 다운 
		 */		
		protected function onListDown(e:MouseEvent):void
		{
			this.backgroundColor = Color.ORANGE;
			this.backgroundAlpha = 1;
			this.invalidateDisplayList();
		}	
		
		/**
		 *		마우스 업 
		 */		
		protected function onListUp(e:MouseEvent):void
		{
			this.backgroundAlpha = 0;
			this.invalidateDisplayList();
		}
		
		/**
		 * 		클릭
		 */		
		protected function onListClick(e:MouseEvent):void
		{
			trace("===> Renderer14 , onListClick : " + this.menuId );
		}	
		
		
	}
}